package com.goods.business.converter;

import com.goods.common.model.business.Product;
import com.goods.common.vo.business.ProductVO;
import org.springframework.beans.BeanUtils;
import org.springframework.util.CollectionUtils;

import java.util.ArrayList;
import java.util.List;

public class ProductConverter {
    /**
     * 转vo
     */
    public static ProductVO converterToProductVO(Product product){
        ProductVO productVO = new ProductVO();
        BeanUtils.copyProperties(product,productVO);
        return productVO;
    }

    /**
     * 转成productVOList
     */
    public static List<ProductVO> converterToProductVOList(List<Product> productList){
        List<ProductVO> productVOList = new ArrayList<>();
        if(!CollectionUtils.isEmpty(productList)){
            for (Product product : productList) {
                ProductVO productVO = converterToProductVO(product);
                productVOList.add(productVO);
            }
        }
        return productVOList;
    }
}
